package com.itheima.Jiuye09;

import java.util.Comparator;
import java.util.TreeMap;

public class MapTest2 {
    public static void main(String[] args) {
        TreeMap<Student2,String> ts = new TreeMap<>(new Comparator<Student2>() {
            @Override
            public int compare(Student2 o1, Student2 o2) {
               int a =  o1.getAge() - o2.getAge();
               a = a==0?o1.getName().compareTo(o2.getName()):a;
                return a;
            }
        });
        Student2 stu = new Student2("王猫",22);
        Student2 stu1 = new Student2("许狗",23);
        Student2 stu2 = new Student2("刘猪",22);
        Student2 stu3 = new Student2("赵蛇",22);
        ts.put(stu,"河南");
        ts.put(stu1,"天津");
        ts.put(stu2,"上海");
        ts.put(stu3,"北京");
        ts.forEach((Student2 key,String value)->{
            System.out.println(key+"---"+value);
        });
       // System.out.println(ts);
    }
}
